package com.hospital.hospitalsystem.base;

import java.io.Serializable;
import java.util.List;

public class PageData<T> extends PageParam implements Serializable {
    private Integer lastPage;
    private Integer total;
    private List<T> data;

    public PageData(){

    }

    public <T>PageData<T> create(Class<T> cls){
        PageData<T> pageList = new PageData();
        return pageList;
    }

    public <T>PageData<T> create(){
        PageData<T> pageList = new PageData();
        return pageList;
    }

    public Integer getTotal() {
        return this.total;
    }

    public PageData<T> setTotal(Integer total) {
        this.total = total;
        return this;
    }

    public List<T> getData() {
        return this.data;
    }

    public PageData<T> setData(List<T> data) {
        this.data = data;
        return this;
    }

    public Integer getLastPage() {
        return this.lastPage;
    }

    public PageData<T> setLastPage(Integer lastPage) {
        this.lastPage = lastPage;
        return this;
    }

    public static <T> PageData<T> of(List<T> data, Integer currentPage,Integer pageSize,Integer total){
        PageData<T> pageList = new PageData();
        pageList.setCurrentPage(currentPage);
        pageList.setPageSize(pageSize);
        pageList.setData(data);
        if(pageSize > 0){
            pageList.setLastPage(total % pageSize == 0 ? total/pageSize : total / pageSize + 1);
        }
        pageList.setTotal(total);
        return pageList;
    }
}
